package com.one2manycall.controller;

import com.one2manycall.service.websocket.UserRegistry;
import com.one2manycall.vo.UserSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 用户管理
 */
@Controller
@RequestMapping("/PlayController")
public class PlayController {


    @Autowired
    private UserRegistry userRegistry;


    //// 页面部分 开始  /////////////////////////////////////
    @GetMapping("/home")
    public String listRoles() {
        return "player_mp4";
    }



    // 这里假设视频文件在项目的"static"目录下，名为video.webm，实际中可按需替换真实路径
    private static final String VIDEO_PATH = "/video.webm";

    @GetMapping("/videoPath")
    @ResponseBody
    public String getVideoPath() {

       return  "/videos/aa.flv";



    }


    @GetMapping("/videoPath/next")
    public String getVideoPathNext() {
        return VIDEO_PATH;
    }




    @GetMapping("/views")
    @ResponseBody
    public Object getViews() {

        ConcurrentMap<String, UserSession> all = userRegistry.getAll();

        HashMap<String, String> stringStringHashMap = new HashMap<>();

        all.entrySet().stream().forEach(a->stringStringHashMap.put(a.getKey(),a.getValue().getSessionId()));

        return stringStringHashMap;
    }


}